﻿using System;
using Unis.Framework.RuleBase.Common;
using Unis.RuleBase.Common;

namespace Unis.Framework.RuleBase.Attributes
{
    [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
    public class ParentProviderAttribute : Attribute
    {
        // Fields
        private bool _AutoOneToOneCheck;
        private string _ForeingKeyField;
        private ObjectRelationType _ObjectRelationType;
        private string _ProviderKeyName;
        private string _ProviderTableName;

        // Methods
        public ParentProviderAttribute(string providerTableName)
            : this(providerTableName, "ID", ObjectRelationType.OneToOne)
        {
        }

        public ParentProviderAttribute(string providerTableName, string keyFieldName, ObjectRelationType objectRelationType)
            : this(providerTableName, keyFieldName, null, objectRelationType)
        {
        }

        public ParentProviderAttribute(string providerTableName, string providerKeyName, string foreingKeyField, ObjectRelationType objectRelationType)
        {
            this._AutoOneToOneCheck = true;
            this._ProviderTableName = providerTableName;
            this._ProviderKeyName = providerKeyName;
            this._ForeingKeyField = foreingKeyField;
            this._ObjectRelationType = objectRelationType;
        }

        // Properties
        public bool AutoOneToOneCheck
        {
            get
            {
                return this._AutoOneToOneCheck;
            }
            set
            {
                this._AutoOneToOneCheck = value;
            }
        }

        public string ForeingKeyField
        {
            get
            {
                return this._ForeingKeyField;
            }
            set
            {
                this._ForeingKeyField = value;
            }
        }

        public ObjectRelationType ObjectRelationType
        {
            get
            {
                return this._ObjectRelationType;
            }
        }

        public string ProviderKeyName
        {
            get
            {
                return this._ProviderKeyName;
            }
        }

        public string ProviderTableName
        {
            get
            {
                return this._ProviderTableName;
            }
        }
    }
}
